package com.gjzhao.fmmall.config.myfilter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description: 扩展内置网关过滤器 创建⼀个类继承AbstractNameValueGatewayFilterFactory，类名必须以GatewayFilterFactory结尾，类名前⾯的部分即为当前⾃定义⽹关过滤器的名字
 * @Author: gjzhao
 * @Date Created in 2022-02-17 9:42 下午
 */
@Component //交由spring管理
public class MyFilterGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public GatewayFilter apply(NameValueConfig config) {

        logger.info("-----进入扩展内置过滤器----");
        logger.info("-----name:{},value:{}----", config.getName(), config.getValue());


        //创建自定义过滤器并返回
        GatewayFilter gatewayFilter = new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

                return chain.filter(exchange);
            }
        };

        return null;
    }
}
